package com.tool;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.*;

public class TheadTool {

    public static void main(String[] args) throws ExecutionException, InterruptedException {


    }

    private static void testFrture() throws InterruptedException, ExecutionException {
        ExecutorService pool = Executors.newCachedThreadPool();
        List<Future<List<String>>> fs = new LinkedList<>();
        for (int i = 1; i < 5; i++) {
            // pool.execute(new thead1());

            Future<List<String>> future = null;
            future = pool.submit(new Callable<List<String>>() {

                @Override
                public List<String> call() throws Exception {
                    List<String> list = new ArrayList<>();
                    Random r = new Random();
                    int o = r.nextInt(3);
                    list.add((o + 1) + "");
                    return list;
                }
            });
            fs.add(future);
        }


        List<String> ss = new LinkedList<>();
        for (Future<List<String>> f : fs) {
            ss.addAll(f.get());
        }

        System.out.println(ss);
    }

}

class thead1 implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());
    }
}
